/*
* File: files_and_reply.h
* Author: Henrik Wistbacka
* --------------------------
* This header file is describing the interface
* to be able to get the header, contents and size of a 
* specific file - if it exists in the folder 
* for the webserver.
*/

#ifndef FILES_AND_REPLY_H
#define FILES_AND_REPLY_H

/* NAMEROOTPAGE is the name of the html file that is sent
* to the client. Set it accordingly to whatever file is needed.*/
#define NAMEROOTPAGE "hemsida.html"

/* SEARCHPATH is the path relative to the executable file
* and is set so it is possible to run it from the 
* MS Visual Studio as well as from the folder containing
* the executable.*/
#define SEARCHPATH (loadServerValues().searchPath) 

#include "logging.h"
#include <stdio.h>

/*
* Function: initFilesAndReply
* Usage: error = initFilesAndReply();
* ------------------------------------------
* This function MUST be the first function used,
* before any other function or function from this
* interface can be used. It reads all files that are in
* the folder SEARCHPATH containing the web files and places the 
* filenames in an array to be compared with when needed.
* The folder containing the web files can be changed in
* the SEARCHPATH above. 
*/
errorT initFilesAndReply();

/*
* Function: getFile
* Usage: error = getFile(fileBuffer, size, HTTPReq);
* ------------------------------------------
* This function returns the header and contents of the 
* requested file in fileBuffer and their length in bytes in size.
* fileBuffer can be used to send the full response to the client.
* If no file is found, fileBuffer is set to just a header - 
* appropriate for the request -  and size set to the length.
* HTTPReq(HTTP Request) must be set to the '\0'
* terminated request header(which contains the name of the file 
* to be served) from the client when called.
*/
errorT getFile(char **fileBuffer, int *size, char **HTTPReq, char *domBuf, char *portBuf);

/*
* Function: fileSize
* Usage: error = fileSize(size, file);
* ------------------------------------------
* This function returns the size of the file file
* in size. 
*/
errorT fileSize(int *size, FILE *file);

/*
* Function: endFilesAndReply
* Usage: error = endFilesAndReply();
* ------------------------------------------
* This function deallocates resources acquired 
* when initFilesAndReply was called.
*/
errorT endFilesAndReply();

#endif